package com.lxl.bt.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * Create by lvxinlong  229608356@qq.com
 * desc不左右滑动的viewpage
 * on
 **/
public class CustomViewPager extends ViewPager {
    private boolean isCanPageScroll = true;


    public CustomViewPager(Context context){
        super(context);
    }

    public CustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!isCanPageScroll) {
            return true;
        }
        return super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (isCanPageScroll == false) {
            return false;
        } else {
            return super.onInterceptTouchEvent(ev);
        }
    }

    public boolean isCanPageScroll() {
        return isCanPageScroll;
    }

    public void setCanPageScroll(boolean canPageScroll) {
        isCanPageScroll = canPageScroll;
    }
}
